<?php

namespace app\admin\validate;
use think\validate;

class Store extends Validate
{
    protected $rule =   [
        'name'  => 'length:1,20',
        'type'  => 'require',
        'store_type'  => 'require',
        'business_hours'  => 'require',
        'phone'  => 'require',
    ];


    protected $message  =   [

        'name.length'      => ['code' => 4023, 'msg' => '长度是1到20位'],
        'type.require'      => ['code' => 4023, 'msg' => '品牌类型必须'],
        'store_type.require'      => ['code' => 4023, 'msg' => '门店类型必须'],
        'business_hours.require'      => ['code' => 4023, 'msg' => '营业时间必须'],
        'phone.require'      => ['code' => 4023, 'msg' => '手机号码必须'],
        // 'name.unique'      => ['code' => 4012, 'msg' => '名称已经存在'],

    ];


    // 自定义验证规则
    protected function checkTitle($value,$rule,$data=[])
    {
        $rule = ['name'    => 'unique:store,name^type='.$data['type']];
        return $this->check($data,$rule);
    }
}
